package com.fresh.service;

import com.fresh.client.GoodsFeignClient;
import com.fresh.dto.ImportGoods;
import com.fresh.entity.FreshGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class ExcelService {

    @Autowired
    private GoodsFeignClient goodsFeignClient;

    public <T> void importExcel(List<T> list) {
        for (T t : list) {
            if(t instanceof ImportGoods){
                System.out.println(t.toString());
                ImportGoods importGoods = (ImportGoods) t;
                //TODO client.add(ImportGoods)
                FreshGoods freshGoods = new FreshGoods();
                freshGoods.setName(importGoods.getName());
                freshGoods.setUnitId(importGoods.getUnitId());
                freshGoods.setNumber(importGoods.getNumber());
                freshGoods.setLossRate(importGoods.getLossRate());
                freshGoods.setCategoryId(importGoods.getCategoryId());
                freshGoods.setUnitWeight(Integer.parseInt(importGoods.getUnitWeight()));
                freshGoods.setSupplierId(importGoods.getSupplierId());
                freshGoods.setDescription(importGoods.getDescription());
                freshGoods.setUpdateTime(LocalDateTime.now());
                freshGoods.setStatus(importGoods.getStatus());
                freshGoods.setPrice(new BigDecimal(importGoods.getPrice()));
                freshGoods.setStock(importGoods.getStock());
                freshGoods.setType(importGoods.getType());
                goodsFeignClient.add(freshGoods);
            }

        }
    }
}
